package net.javacloud.service;

import org.eclipse.jetty.util.HostMap;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;

import java.io.IOException;
import java.util.Map;

/**
 * Created by Crowhyc on 2016/6/24.
 */
public class Tester {

    static Map<String, MsgSender> connectionMap = new HostMap<>();
    static String host = "localhost";//openfireIp地址
    static int testNum = 200;//测试登录人数
    static int sendInterval = 10;//消息发送间隔(秒)
    static String msg = "测试消息";//发送消息的头
    static String uname = "test";//用户名头
    static String pwd = "123";//密码
    static boolean flag = true;//是否关闭
    static int durationTime = 60 * 3;//持续时间(秒)
    static int loginInterval = 0;//登录间隔(秒)
    static String roomId = "test003";//房间名
    static String adminName = "admin";//管理员账号
    static String adminPwd = "hychyc";//管理员密码


    public static void main(String[] args) throws XMPPException, IOException, SmackException, InterruptedException {
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < testNum; i++) {
            String username = uname + i;
            if (AccountRegister.userRegister(username, pwd)) {
                MsgSender msgSender = new MsgSender(username, pwd, msg, sendInterval, roomId);
                Thread t = new Thread(msgSender);
                t.start();
                System.out.println(username + "已经登录成功");
            }
            Thread.sleep(loginInterval * 1000);
        }
        while (flag) {
            if (System.currentTimeMillis() >= startTime + (durationTime * 1000)) {
                flag = false;
            }
            Thread.sleep(1000);
        }
        System.out.println("测试结束");

    }

}
